<template>
  <div>
      <div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到天天生鲜!</div>
			<div class="fr">
                
				<div class="login_btn fl">
					<a href="/user/login">登录</a>
					<span>|</span>
					<a href="/user/register">注册</a>
				</div>
                
				<div class="user_link fl">
					<span>|</span>
					<a href="/user/">用户中心</a>
					<span>|</span>
					<a href="/cart/">我的购物车</a>
					<span>|</span>
					<a href="/user/order/1">我的订单</a>
				</div>
			</div>
		</div>		
	</div>




	<div class="search_bar clearfix">
		<a href="/" class="logo fl"><img src="../assets/images/logo.png"></a>
		<div class="search_con fl">
            <form method="get" action="/search">
                <input type="text" class="input_text fl" name="q" placeholder="搜索商品" v-model="name">
                <input type="button" class="input_btn fr" name="" value="搜索" @click="search">
            </form>
		</div>
		<div class="guest_cart fr">
			<a href="/cart/" class="cart_name fl">我的购物车</a>
			<div class="goods_count fl" id="show_count"></div>
		</div>
	</div>




	<div class="navbar_con">
		<div class="navbar clearfix">
			<div class="subnav_con fl">
				<h1>全部商品分类</h1>
				<span></span>
				<ul class="subnav">
                    
				</ul>
			</div>
			<ul class="navlist fl">
				<li><a href="">首页</a></li>
				<li class="interval">|</li>
				<li><a href="">手机生鲜</a></li>
				<li class="interval">|</li>
				<li><a href="">抽奖</a></li>
			</ul>
		</div>
	</div>
    
    
	<div class="breadcrumb">
		<a href="#">{{name}}</a>
		<span>></span>
		<a href="#">搜索结果如下:</a>
	</div>

	<div class="main_wrap clearfix">
        <ul class="goods_type_list clearfix">
            
            <li v-for="goods in goods_list" :key="goods.id">
                <router-link  :to="'/detail?id='+goods.id"><img :src="'http://127.0.0.1:8000'+goods.pic"></router-link>
                <h4><router-link  :to="'/detail?id='+goods.id">{{goods.name}}</router-link></h4>
                <div class="operate">
                    <span class="prize">￥{{goods.price}}</span>
                    <span class="unit">{{goods.price}}/{{goods.unit}}</span>
                    <a href="#" class="add_goods" title="加入购物车"></a>
                </div>
            </li>
            
            
        </ul>
        <div class="pagenation">
				        <a href="javascript:void" class="active" v-for="num in num_list" :key="num" @click="gopage(num)">{{num}}</a>
			</div>
			
	</div>
	<MyCertification></MyCertification>
  </div>
</template>

<script>
import axios from 'axios'
import mycertification from './common/Certification'
export default {
	components:{
		'MyCertification':mycertification
	},
    data(){
        return{
		   name:'',
		   goods_list:[],
		   num_list:[]
        }
    },methods:{
		search(){
		// axios.get('http://127.0.0.1:8000/goodssearch',{'params':{'name':this.name}}).then(resp=>{
		// 	console.log(resp.data)
		// 	this.goods_list=resp.data.data
		// }).catch(error=>{
		// 	console.log(error)
		// })
		this.gopage(1)
		},
		gopage(num){
            axios.get('http://127.0.0.1:8000/goodssearch',{'params':{'name':this.name,'num':num}}).then(resp=>{
                console.log(resp.data)
                this.goods_list=resp.data.data
                this.num_list=resp.data.num_list
            }).catch(error=>{
                console.log(error)
            })
        },
	}
}
</script>

<style>

</style>